eth-json-rpc-errors
Errors for JSON RPC 2.0 and ETH JSON RPC.
Supported Errors
- All JSON RPC 2.0 errors (see "5.1 Error object")
- ETH JSON RPC
- Proposed errors in EIP 1193 (see "Error object and codes")
Usage
Installation: npm install eth-json-rpc-errors
Import using ES6 syntax (no default) or Node require
.
Errors API
import { errors as rpcErrors } from 'eth-json-rpc-errors'
response.error = rpcErrors.methodNotFound(
optionalCustomMessage, optionalData
)
response.error = rpcErrors.eth.unauthorized(
optionalCustomMessage, optionalData
)
response.error = rpcErrors.eth.unauthorized(null, optionalData)
response.error = rpcErrors.eth.unauthorized(optionalCustomMessage)
response.error = rpcErrors.eth.unauthorized()
response.error = rpcErrors.methodNotFound()
response.error = rpcErrors.server(
-32031, optionalCustomMessage, optionalData
)
response.error = rpcErrors.eth.custom(
1001, requiredMessage, optionalData
)
Other Exports
import {
IRpcErrors, IJsonRpcError, IEthJsonRpcError, ISerializeError
} from 'eth-json-rpc-errors/@types'
import { JsonRpcError, EthJsonRpcError } from 'eth-json-rpc-errors'
import { serializeError } from 'eth-json-rpc-errors'
response.error = serializeError(maybeAnError)
const fallbackError = { code: 4999, message: 'My custom error.' }
response.error = serializeError(maybeAnError, fallbackError)
{
code: -32603,
message: 'Internal JSON-RPC error.'
}
import { getMessageFromCode, ERROR_CODES } from 'eth-json-rpc-errors'
const message1 = getMessageFromCode(someCode)
const message2 = getMessageFromCode(someCode, myFallback)
const message3 = getMessageFromCode(someCode, null)
const code1 = ERROR_CODES.jsonRpc.parse
const code2 = ERROR_CODES.eth.userRejectedRequest
const message4 = getMessageFromCode(code1)
const message5 = getMessageFromCode(code2)
License
MIT